﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnoWeb.CEND.BL.Service.Page
{
    using InnoWeb.CEND.BL.Infrastructure;
    using InnoWeb.CEND.Core.Model.Page;
    using InnoWeb.CEND.Data;
    using InnoWeb.CEND.Data.Infrastructure;

    public class PageItemService : IService<PageItem>
    {
        private readonly GenericRepository<PageItem> _pageItemRepository;
        private readonly IUnitOfWork _unitOfWork;

        public PageItemService(IUnitOfWork unitOfWork, GenericRepository<PageItem> pageItemRepository)
        {
            this._unitOfWork = unitOfWork;
            this._pageItemRepository = pageItemRepository;
        }

        public IQueryable<PageItem> GetAllElements()
        {
            return _pageItemRepository.GetAll();
        }

        public PageItem GetElementById(int id)
        {
            return _pageItemRepository.GetById(id);
        }

        public void CreateElement(PageItem entity)
        {
            _pageItemRepository.Insert(entity);
        }

        public void UpdateElement(PageItem entity)
        {
            _pageItemRepository.Update(entity);
        }

        public void DeleteElement(int id)
        {
            _pageItemRepository.Delete(id);
        }

        public void SaveChanges()
        {
            this._unitOfWork.SaveChanges();
        }
    }
}
